home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / shar.lha / shar / cwd.c next >
C/C++ Source or Header  |  1987-12-03  |  941b  |  67 lines

  1. /*
  2. **  Return current working directory.  Something for everyone.
  3. */
  4. /* LINTLIBRARY */
  5. #include "shar.h"
  6. RCS("$Header: cwd.c,v 1.3 87/03/02 11:03:21 rs Exp $")
  7.  
  8.  
  9. #ifdef    PWDGETENV
  10. /* ARGSUSED */
  11. char *
  12. Cwd(p, i)
  13.     char    *p;
  14.     int         i;
  15. {
  16.     char    *q;
  17.  
  18.     return((q = getenv(PWDGETENV)) ? strcpy(p, q) : NULL);
  19. }
  20. #endif    /* PWDGETENV */
  21.  
  22.  
  23. #ifdef    GETWD
  24. /* ARGSUSED1 */
  25. char *
  26. Cwd(p, size)
  27.     char    *p;
  28.     int         size;
  29. {
  30.     return(getwd(p) ? p : NULL);
  31. }
  32. #endif    /* GETWD */
  33.  
  34.  
  35. #ifdef    GETCWD
  36. char *
  37. Cwd(p, size)
  38.     char    *p;
  39.     int         size;
  40. {
  41.     return(getcwd(p, size) ? p : NULL);
  42. }
  43. #endif    /* GETCWD */
  44.  
  45.  
  46. #ifdef    PWDPOPEN
  47. extern FILE    *popen();
  48. char *
  49. Cwd(p, size)
  50.     char    *p;
  51.     int         size;
  52. {
  53.     FILE    *F;
  54.     int         i;
  55.  
  56.     if (F = popen("exec pwd", "r")) {
  57.     if (fgets(p, size, F) && p[i = strlen(p) - 1] == '\n') {
  58.         p[i] = '\0';
  59.         (void)fclose(F);
  60.         return(p);
  61.     }
  62.     (void)fclose(F);
  63.     }
  64.     return(NULL);
  65. }
  66. #endif    /* PWDPOPEN */
  67.